<!--
=============================================================
WebIntelligence(r) Report Panel
Copyright(c) 2001-2005 Business Objects S.A.
All rights reserved

Use and support of this software is governed by the terms
and conditions of the software license agreement and support
policy of Business Objects S.A. and/or its subsidiaries. 
The Business Objects products and technology are protected
by the US patent number 5,555,403 and 6,247,008

=============================================================
--><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Title zone</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="javascript" src="../../../../dhtmllib/dom.js"></script>
<script language="javascript" src="../../../../dhtmllib/dialog.js"></script>
<script language="javascript" src="../../../scripts/CommonWom.js"></script>
<script language="javascript" src="../../../../dhtmllib/treeview.js"></script>
<script language="javascript" src="../../../../dhtmllib/menu.js"></script>
<script language="javascript" src="../../../../dhtmllib/palette.js"></script>
<script language="javascript">
p = parent
if(p._dictionaryStructure == null) 
{
p.ajaxDictionaryStructure(p.fillDictionaryStructure);
}
if(p._formulaFcts == null)
{        
var url =  p._root + "incFunctions" + p._appExt
url += p.urlParams(false,true)
includeScript(url) 
}
</script>
<script language="javascript">
_timeInterval=null
_timeWait=null
initDom(p._root + "../dhtmllib/images/"+p._skinName+"/", p._lang, p, "variableEditorDlg");
_fromLPane = (requestQueryString(window,"fromLPane") == 'yes') 
_LPane=_fromLPane?p.leftPane.getFrame():null
_isFormulaEditor = (requestQueryString(window,"isFormulaEdit") == 'yes')
_isApplyMode = false;
_isFromOtherDialog = (requestQueryString(window,"isFromOtherDialog") == 'yes')
if (_isFromOtherDialog)
{
_callBackIn = requestQueryString(window,"callbackin");
_callBackOut = requestQueryString(window,"callbackout");
}
_defaultQualif = (requestQueryString(window,"qualification"));
_Qualification = _defaultQualif?_defaultQualif:"dimension";
_associatedDimName = "选择一个维"
_associatedDimID = ""
_baseAssociatedDimID = ""
_isValidFormula = false
_isEditing = p.formulaEdition
_objName=""
_objId=""
_objFormula=""
_objDataType=""
_ddText=""
_helpText=""
_arrLogOp=new Array("=","<","<=","<>",">",">=",".","+","-","/","*","(",")")
function newIconObj(name,icon,desc)
{
var o=new Object()
o.name=name
o.icon=icon
o.desc=desc?desc:""
return o;
}
_shownPopup=false
_arrSeparators=new Array(" ","=",".",",",";","(",")","[","]","{","}","&","\"","'","|","@","+","-","*","/","<",">","\\","\n","\t")
_arrMatchTxt=new Array
_arrObj=new Array
_arrFctOpe=new Array
_arrAvailableObjects=new Array
_lastMatchTxt=""
_currentMatchTxt=""
_oldFormula=""
_newFormula=""
_firstPart=""
_lastPart=""
_cursorPos=-1
_formulaTxtFocus=false;
initialized=false
variableEditorDlg=null
_wDlg=550;
_hVarHeader=130;
_hDlg=_isFormulaEditor?(580-_hVarHeader):580;
_minDlgWidth=500;
_minDlgHeight=_isFormulaEditor?(450-_hVarHeader):450;
_wName=235;
_wType=235;
_wCombo=235;
_wLinkedDim=200;
_nLines=7;
_nCols=80;
_wDicTree=160;
_hDicTree=100;
_wFctTree=160;
_hFctTree=100;
_wOpeTree=_ie?176:176; 
_hOpeTree= 50;
_wFrame=480;
_hFrame=50;
_wIcon=_ie?20:24;
_hIcon=21;
_wWindow=1000;
_hWindow=500;
_warningModif = null
function loadDialog()
{
if (!initialized)
{
initialized=true
urlImg = p._root + p._img
variableEditorDlg= newDialogBoxWidget("variableEditorDlg","创建新变量",_wDlg,_hDlg,okCB,closeDlg,false)
variableEditorDlg.setResize(resizeDlgCB,_minDlgWidth,_minDlgHeight);
textName= newTextFieldWidget("variableTextName",null,50,updateButtons,null,true,"变量名称",_wName)
textTypeZone= newTextFieldWidget("variableType",null,50,updateButtons,null,true,"对象返回的数据的类型",_wLinkedDim)
qualifList =  new_CustomCombo({id:"variableQualificationList",width: _wCombo, tooltip:"对象限定",changeCB: updateLinkBtn, icon:p._kindIconArr[p._dim]});
headerZone= newWidget("variableHeaderZone");
linkDimZone= newWidget("variableLinkedDimZone");
linkedDim= newTextFieldWidget("variableLinkedDim",null,null,null,null,true,"关联维",_wLinkedDim)
linkButton= newButtonWidget("variableLinkButton","...","displayDimList()",15,null,"维的显示列表")
formulaTxt= newTextAreaWidget("variableExprTxt",_nLines,_nCols,null,formulaTxt_change,null,formulaTxt_cancel)
dicTree= newTreeWidget('variabledicTree', _wDicTree, _hDicTree, urlImg + "qualificationIcons.gif", clickCB, dclickCB)
dicTree.setTooltipOnMouseOver(true) 
fctTree= newTreeWidget('variablefctTree', _wFctTree, _hFctTree, urlImg + "qualificationIcons.gif", clickCB, dclickCB)
opeTree= newIconListWidget("variableopeTree",_wOpeTree,_hOpeTree,urlImg + "qualificationIcons.gif", clickCB, dclickCB,"treeNoBorder");
opeTree.borderW=0
helpFctZone= newFrameZoneWidget("variableHelpFctZone",_wFrame,_hFrame,true)
helpFctScroll= newScrolledZoneWidget("variableHelpFctScroll",0,0,_wFrame,_hFrame,"dlgContent")
helpFctArea= newWidget("variableHelpFctArea")
validateFormulaIcn= new_IconWidget({ id:'variableValidateF', 
                                          clickCB:validateFormula, 
  tooltip:'验证公式',
                                          dx:32, dy:0, src:urlImg+"formula.gif", w:16, h:16, icontype:_midGroupLR16});
   resetFormulaIcn       = new_IconWidget({ id:'variableResetF', 
                                            clickCB:resetFormula, 
tooltip:'取消公式',
                                            dx:16, dy:0, src:urlImg+"formula.gif", w:16, h:16, icontype:_midGroupLR16});
hSplitZone = new_SplitZoneWidget({id:"variableHSplitZone",isHori:false,
resizeCB:szResizeCB,
width:_minDlgWidth-10,
height:100,
pos:80,
overflow:"hidden"
});
hSplitZone.setMinimalDimensions(65, 67)
OKButton= newButtonWidget("variableOKButton","确定","okCB(false)",60)
CancelButton= newButtonWidget("variableCancelButton","取消","closeDlg()",60)
HelpButton= newButtonWidget("variableHelpButton","帮助",null,60)
ApplyButton= newButtonWidget("variableApplyButton","应用","okCB(true)",60)
completionPopup= newIconListPopupWidget("cpopup",150,150,urlImg + "qualificationIcons.gif",completion_click,completion_insert)
completionList= completionPopup.getList();
completionList.setMouseOverCB(completion_mouseOver)
completionPopup.cancelCB = formulaTxt_cancel
associatedDimDlg= newDialogBoxWidget("associatedDimDlg","对象和变量",250,300,associatedDimOK,associatedDimClose,false)
dimTree= newTreeWidget("associatedDimTree", 240, 220, urlImg + "qualificationIcons.gif",updateDimOKBtn,validateDimCB);
dimTree.setTooltipOnMouseOver(true) 
dimOK= newButtonWidget("associatedDimOK","确定","associatedDimOK()",60)
dimCancel= newButtonWidget("associatedDimCancel","取消","associatedDimClose()",60)
iconLogOp=new Array
for(var i=0;i<_arrLogOp.length;i++)
{
iconLogOp[i]=newIconWidget("iconLogOp"+i,null,clickCB,_arrLogOp[i])
iconLogOp[i].margin=0
iconLogOp[i].txtAlign='center'
iconLogOp[i].border=1
iconLogOp[i].txtNoPadding=true
iconLogOp[i].resize(_wIcon,_hIcon)
}
validationDlgMsg= "正确定义了公式。"
dicTree.setDragDrop(dragCB, acceptDropCB, dropCB)
fctTree.setDragDrop(dragCB, acceptDropCB, dropCB)
opeTree.setDragDrop(dragCB, acceptDropCB, dropCB)
variableEditorDlg.attachDefaultButton(OKButton);
associatedDimDlg.attachDefaultButton(dimOK);
}
var firstTime = (_curWin.variableEditorInitialized!=true)
if (_curWin.variableEditorInitialized!=true)
{
_curWin.variableEditorInitialized=true
var iconLogOpHTML='<table class="dialogzone" style="border:1px solid #c6c6c6;border-collapse:collapse" cellpadding="0" cellspacing="0" border="0"><tr>'
for(var i=0;i<_arrLogOp.length;i++)
{
iconLogOpHTML+='<td style="border:1px solid #c6c6c6">'+iconLogOp[i].getHTML()+'</td>'
if(i==5)iconLogOpHTML+='</tr><tr>'
}
iconLogOpHTML+='</tr></table>'
var firstHTML = '<table class="dialogzone" cellpadding="2" cellspacing="0" border="0">'+
'<tr>'+
'<td>'+formulaTxt.getHTML()+'</td>'+
'<td style="padding-left:4px;" valign="top">'+
                        '<table border="0"  cellpadding="0" cellspacing="0"><tbody>' +
                        '<tr><td>' + 
                        validateFormulaIcn.getHTML()+
                        '</td></tr>' +
                        '<tr><td style="padding-top:4px;">' + 
                        resetFormulaIcn.getHTML()+
                        '</td></tr>' +
                        '</tbody></table>'+
'</td>'+
'</tr>'+
'</table>';
var secondHTML = '<table class="dialogzone" cellpadding="2" cellspacing="0" border="0">'+
'<tr>'+
'<td>可用对象</td>'+
'<td>可用函数</td>'+
'<td>可用运算符</td>'+
'</tr>'+
'<tr>'+
'<td>'+dicTree.getHTML()+'</td>'+
'<td>'+fctTree.getHTML()+'</td>'+
'<td>'+
'<table class="solidBorder" style="padding:0px;background-color:#E4E4EC;" cellpadding="0" cellspacing="0" border="0"><tr><td>'+
iconLogOpHTML+
'</td></tr>'+
'<tr><td>'+opeTree.getHTML()+
'</td></tr>'+
'</table>'+
'</td>'+
'</tr>'+
'</td></tr>'+
'</table>';
hSplitZone.setFirstZoneHTML(firstHTML);
hSplitZone.setSecondZoneHTML(secondHTML);
var hSplitZoneHTML = hSplitZone.getHTML();
targetApp
(
completionPopup.getHTML()+
variableEditorDlg.beginHTML()+
'<table class="dialogzone" cellpadding="0" cellspacing="0" border="0" width="100%">'+
'<tr><td>'+
'<div id="variableHeaderZone">'+
'<table width="100%" class="dialogzone" cellpadding="1" cellspacing="0" border="0">'+
'<tr><td colspan="4">' + getGroupSep({title:"定义"}) + '</td></tr>'+
'<tr>'+
'<td>名称: </td>'+
'<td width="15"></td>'+
'<td>类型：</td>'+
'</tr>'+
'<tr>'+
'<td>'+textName.getHTML()+'</td>'+
'<td width="15"></td>'+
'<td>'+textTypeZone.getHTML()+'</td>'+
'</tr>'+
'<tr>'+
'<td>限定: </td>'+
'<td rowspan="2" width="15"></td>'+
'<td rowspan="2">'+
'<table id="variableLinkedDimZone" class="dialogzone" cellpadding="1" cellspacing="0" border="0">'+
'<tr><td colspan="2">关联维: </td></tr>'+
'<tr>'+
'<td>'+linkedDim.getHTML()+'</td>'+
'<td>'+linkButton.getHTML()+'</td>'+
'</tr>'+
'</table>'+
'</td>'+
'</tr>'+
'<tr>'+
'<td>'+qualifList.getHTML()+'</td>'+
'</tr>'+
'</table>'+
'</div>'+
'</td></tr>'+
'<tr><td>' + getGroupSep({title:"公式"}) + '</td></tr>'+
'<tr><td>'+
hSplitZoneHTML+
'</td></tr>'+
'<tr><td>' + getGroupSep({title:"说明"}) + '</td></tr>'+
'<tr><td>'+
helpFctZone.beginHTML()+
helpFctScroll.beginHTML()+
'<div id="variableHelpFctArea" width="20"></div>'+
helpFctScroll.endHTML()+
helpFctZone.endHTML()+
'</td></tr>'+
'<tr><td align="right">'+
'<table cellpadding="5" cellspacing="0" border="0">'+
'<tr>'+
'<td>'+OKButton.getHTML()+'</td>'+
'<td>'+CancelButton.getHTML()+'</td>'+
'<td>'+ApplyButton.getHTML()+'</td>'+
'<td>'+HelpButton.getHTML()+'</td>'+
'</tr>'+
'</table>'+
'</td></tr>'+
'</table>'+
variableEditorDlg.endHTML()+
associatedDimDlg.beginHTML()+
'<table class="dialogzone" cellpadding="0" cellspacing="2" border="0">'+
'<tr><td>选择要与明细关联的维</td></tr>'+
'<tr><td>'+ dimTree.getHTML()+'</td></tr>'+
'<tr><td align="right">'+
'<table cellpadding="5" cellspacing="0" border="0">'+
'<tr>'+
'<td>'+dimOK.getHTML()+'</td>'+
'<td>'+dimCancel.getHTML()+'</td>'+
'</tr>'+
'</table>'+
'</td></tr>'+
'</table>'+
associatedDimDlg.endHTML()
)
}
variableEditorDlg.init();
textName.init();
textTypeZone.init();
textTypeZone.setDisabled(true);
qualifList.init();
headerZone.init();
linkDimZone.init();
linkedDim.init();
linkButton.init();
linkedDim.setDisabled(true);
validateFormulaIcn.init();
resetFormulaIcn.init();
OKButton.init();
CancelButton.init();
ApplyButton.init();
ApplyButton.setDisplay(false)
HelpButton.init();
HelpButton.setDisplay(false)
formulaTxt.init();
hSplitZone.init();
formulaTxt.layer.ondrop=textDropCB
formulaTxt.layer.onfocus=formulaTxt_focus
formulaTxt.layer.onblur=formulaTxt_blur
formulaTxt.layer.onclick=formulaTxt_storeCaret
formulaTxt.layer.onselect=formulaTxt_storeCaret
formulaTxt.layer.onkeyup=formulaTxt_storeCaret
helpFctZone.init();
helpFctScroll.init();
helpFctArea.init();
dicTree.init()
p.fillDictionaryTree(dicTree,self,null);
fctTree.init()
opeTree.init()
buildFctTree()
buildOpeTree()
fctTree.rebuildHTML()
opeTree.rebuildHTML()
completionList.init()
for(var i=0;i<_arrLogOp.length;i++)
{
iconLogOp[i].init()
}
initDialog()
textName.focus()
textName.select()
associatedDimDlg.init();
dimTree.init();
dimOK.init();
dimOK.setDisabled(true);
dimCancel.init();
 _timeInterval=setInterval("updateButtons()",100)
 _oldFormula= formulaValue();
_newFormula = formulaValue();
variableEditorDlg.show(true);
_curWin.variableEditorLastState=_isFormulaEditor?"formula":"variable";
_warningModif = true 
}
function filterDimension()
{
return p.getFilteredDictionaryByKinds(_ObjType.dim, _ObjType.hierarchy, null); 
}
function initDialog()
{
if(_isEditing)
{
_objName=getVariableName()
_objId=getVariableId()
_objFormula=getVariableDefinition()
_objDataType=getVariableDataType()
OKButton.setDisabled(false)
ApplyButton.setDisabled(false)
variableEditorDlg.setTitle("编辑变量")
}
else 
{
_objName=""
_objId=""
_objFormula=getFormulaFromFormulaBar()
OKButton.setDisabled(true)
ApplyButton.setDisabled(true)
variableEditorDlg.setTitle("创建新变量")
}
textName.setValue(_objName)
textTypeValue(_objDataType)
if (_isFromOtherDialog)
{
ApplyButton.setDisabled(true)
eval('formulaValue('+_callBackIn+'())');
}
else
formulaValue(_objFormula)
validateFormulaIcn.setDisabled(true)
switch (getVariableQualification())
{
case p._msr:
_Qualification = "measure"
break;
case p._dtl:
_Qualification = "detail"
fillAssociatedDimInfo();
break;
default:
break;
}
qualifList.del();
var img = p._kindIconArr[p._dim];
qualifList.add("维","dimension",true,img);
img = p._kindIconArr[p._msr];
qualifList.add("度量","measure",false,img);
img = p._kindIconArr[p._dtl];
qualifList.add("明细", "detail", false,img);
qualifList.valueSelect(_Qualification);
linkedDim.setValue(_associatedDimName?_associatedDimName:"选择一个维");
if(_Qualification=="detail")
linkDimZone.show(true);
else
linkDimZone.show(false);
headerZone.setDisplay(!_isFormulaEditor);
if(_isFormulaEditor)
variableEditorDlg.setTitle("公式编辑器")
fillAvailableObjectsList()
}
function resizeDlgCB(newW,newH)
{
if(newW<_minDlgWidth) newW = _minDlgWidth;
if(newH<_minDlgHeight) newH = _minDlgHeight;
var needReduceHeight=(_curWin.variableEditorLastState =="variable" && _isFormulaEditor);
var needEnlargeHeight=(_curWin.variableEditorLastState =="formula" && !_isFormulaEditor);
var marge=5, hTitle=27, wIcn=35, hDesc=90, hBtn=40, hFmlHeader=20, increment=10, hFormulaMin=50;
var magicNumber=27;
var hVarDef=_isFormulaEditor?20:_hVarHeader;
var hFrame = _hFrame;
var posSZone=null;
var hMinLimit = _isFormulaEditor? (460 - _hVarHeader): 460;
var hTreeMaxLimit = 200; 
var hTreeMinLimit = 100; 
if(needReduceHeight)
{
newH = newH-_hVarHeader;
}
if(!_ie && needEnlargeHeight)
{
newH = newH+_hVarHeader;
}
if(newW>winWidth()) newW = Math.max(_minDlgWidth,(winWidth()-10));
if(newH>winHeight()) newH = Math.max(_minDlgHeight,(winHeight()-10));
var newRowsHeight=oldRowsHeight=formulaTxt.getHeight();
if(newH < hMinLimit)
{
newRowsHeight=hFormulaMin;
posSZone=newRowsHeight+marge*2;
hFrame = 30;
hDesc = 70;
}
var hSZone = newH - (hTitle+hVarDef+hFmlHeader+hDesc+hBtn)+ (_isFormulaEditor?11:18);
var wSZone = newW-marge*2;
var hSZoneMax = Math.max(100,(hSZone - 100));
hSplitZone.resize(wSZone,hSZone,posSZone,65, hSZoneMax);
var hText = Math.round(hSplitZone.getFirstZoneDimensions().height);
var hTree = hSZone - ( hText+magicNumber);
var wTree = newW - (_wOpeTree + marge*8);
var hOldTree = dicTree.getHeight();
if(hOldTree>=hTree && hTree<hTreeMinLimit )
{
hText = hSZone - (hTree+magicNumber);
newRowsHeight = hText-marge*2;
posSZone = hText;
hSplitZone.resize(null,null,posSZone,null, null);
}
else if(hOldTree>hTree && hTree>hTreeMinLimit && oldRowsHeight>hFormulaMin ) 
{
hText = hText-increment;
var hTree2 = hSZone - ( hText+magicNumber);
if(hTree2<hTree)
{
newRowsHeight = hText-marge*2;
posSZone = hText;
hSplitZone.resize(null,null,posSZone,null, null);
}
}
else if(hOldTree<hTree && hTree>hTreeMaxLimit) 
{
hText = hText+increment;
newRowsHeight = hText-marge*2;
hTree = hSZone - ( hText+magicNumber);
posSZone = hText;
hSplitZone.resize(null,null,posSZone,null, null);
}
var newColsWidth = newW-wIcn-marge*6;
formulaTxt.resizePixels(newColsWidth,_ie?(newRowsHeight-4):(newRowsHeight-2));
dicTree.resize(Math.round(wTree/2),hTree);
fctTree.resize(Math.round(wTree/2),hTree);
opeTree.resize(null,hTree+4-(_hIcon)*2-marge*2);
helpFctZone.resize((newW-marge*8),hFrame);
helpFctScroll.resize((newW-marge*8),hFrame);
variableEditorDlg.resize(newW,newH);
}
function szResizeCB()
{
var o=this,marge=5;
var dim = o.getFirstZoneDimensions();
var newRowsHeight = dim.height-marge*2;
formulaTxt.resizePixels(null,_ie?(newRowsHeight-4):(newRowsHeight-2));
dim = o.getSecondZoneDimensions();
var hTree = dim.height - marge*4;
dicTree.resize(null,hTree);
fctTree.resize(null,hTree);
opeTree.resize(null,hTree+3-(_hIcon*2+marge*2));
}
function getQualification()
{
return qualifList.getSelection().value;
}
function getVariableName()
{
if(!_fromLPane)
return p.getVariableName()
else
{
if(_LPane) 
{
var items =_LPane.dicTree.getSelections()
if (items.length > 0) {
var data=items[0].userData; 
return data?data.name:"";
} else {
return ""
}
}
}
}
function getVariableId()
{
if(!_fromLPane)
return p.getVariableId()
else
{
if(_LPane) 
{
var items =_LPane.dicTree.getSelections()
if (items.length > 0) {
var data=items[0].userData; 
return data?data.id:"";
} else {
return ""
}
}
}
}
function getVariableDefinition()
{
if(!_fromLPane)
return p.getVariableDefinition()
else
{
var items =_LPane.dicTree.getSelections()
var data=items[0].userData; 
if(_isEditing)
return data?data.formula:"";
else
return ""
}
}
function getVariableDataType()
{
if(!_fromLPane)
return p.getVariableDataType()
else
{
var items =_LPane.dicTree.getSelections()
var data=items[0].userData; 
if(_isEditing)
return data?data.dataType:"";
else
return ""
}
}
function getFormulaFromFormulaBar()
{
if (!_fromLPane)
{
if(_defaultQualif)
return "";
if(p.formulaText)
return p.formulaText.getValue();
if(p.formulaExpression)
return p.formulaExpression;
}
else 
{
return ""
}
}
function getVariableQualification()
{
if(!_fromLPane)
return p.getVariableQualification()
else
{
if(_LPane) 
{
var items =_LPane.dicTree.getSelections()
if (items.length > 0) {
var data=items[0].userData;
return data?data.kind:null
} else {
return null
}
}
}
}
function fillAvailableObjectsList()
{
var dico = p.getDictionary();
if (dico == null) 
{
p.ajaxDictionaryStructure(p.fillDictionaryStructure);
setTimeout("fillAvailableObjectsList()", 100);
return;
}
var clone = p.getCloneDictionary();
if(clone.flatDico == null) return;
for(var i=0; i<clone.flatDico.size();i++)
{
arrayAdd(window,"_arrAvailableObjects",clone.flatDico[i])
}
}
function fillAssociatedDimInfo()
{
var associatedDimID = "";
if(!_fromLPane)
associatedDimID =  p.getAssociatedDim()
else
{
if(_LPane) 
{
var items =_LPane.dicTree.getSelections()
var data=items[0].userData;
associatedDimID = data?data.associatedDim:null
}
}
_associatedDimID = associatedDimID?associatedDimID:"";
_associatedDimName =  getDimensionFromID(_associatedDimID);
_baseAssociatedDimID = _associatedDimID;
}
function getDimensionFromID(id)
{
if(id == null || id=="")
return "";
var obj = p.getDictionaryObjectFromId(id);
if(obj && obj.name) return obj.name
return "";
}
function getURLParams()
{
if(!_fromLPane)
return p.urlParams(false,true)
else
return p.urlParamsNoBID()
}
function validateStringFormula()
{
var f= formulaValue()
var bAddQuotes=true;
if(f.substring(0,1)!="" && f.substring(0,1)!= "=" && !_isFormulaEditor) 
{
if(f.substring(0,1)=='\"') bAddQuotes=false;
var newf='='+(bAddQuotes?'"'+f.replace(/"/g,"\\\"")+'"':f)
formulaValue(newf)
}
}
//the syntax is valid or invalid
//OK button can be disable or not
function setValidateFormula(b)
{
_isValidFormula=b
}
//set or get the formulaTxt value
function formulaValue(s)
{
if(s!=null)
formulaTxt.setValue(s)
else
return remSpaceAround(formulaTxt.getValue())
}
//set or get the textType value
function textTypeValue(s)
{
if(s!=null)
{
if (s == "") 
textTypeZone.setValue("未定义")
else 
{
textTypeZone.setValue(p._labDataType[s])
}
}
}
//display error and put cursor at the right position
function showMyAlertDialog(msg,index)
{
if(msg == "")
p.showAlertDialog(validationDlgMsg,null,0); //formula ok
else
{
p.showAlertDialog(msg,null,2,_codeWinName+".setCursorErrorPosition("+index+")"); 
}
}
function setCursorErrorPosition(index)
{
setTimeout("delayedRestoreErrorCursor("+index+")",100);
}
function delayedRestoreErrorCursor(idx)
{
formulaTxt.focus();
var lyr=formulaTxt.layer
if (lyr.createTextRange) //ie
{
var rng = _curDoc.selection.createRange().duplicate();
rng.move("character",idx)
rng.select();
}
else if(lyr.setSelectionRange )//mozilla
{
lyr.setSelectionRange(idx,idx);
}
}
//disable or enable validate and oK buttons
function updateButtons()
{
//update validate button
var f=formulaValue();
if (f!="")
validateFormulaIcn.setDisabled(false)
else 
validateFormulaIcn.setDisabled(true)
//update ok button
var disable = true
var sName = remSpaceAround(textName.getValue())
if((sName!="")&& (f!="")) //create variable
disable=false;
if(_isFormulaEditor && (f!="")) //formula editor
disable=false;
OKButton.setDisabled(disable);
ApplyButton.setDisabled(((_isFromOtherDialog)?true:disable));
return disable; 
}
//restore the cursor position in the formulaTxt after close the popup
function delayedRestoreCursor()
{
formulaTxt.focus()
var lyr=formulaTxt.layer
if (lyr.createTextRange) //ie
{
var rng = _curDoc.selection.createRange().duplicate();
rng.move("character",-(lyr.value.length-_cursorPos))
rng.select();
//alert('insert')
}
else if(lyr.setSelectionRange )//mozilla
{
lyr.setSelectionRange(_cursorPos,_cursorPos);
}
}
//====================================================================
//CALLBACK FUNCTIONS
//====================================================================
function okCB(bApplyBtn)
{
_isApplyMode =bApplyBtn!=null?bApplyBtn:false;
//blindage pour cas special:
//when we use IE contextmenu to remove text, no key event is send
//setInterval() is not sufficient to be safe
var disableOK=updateButtons()
if(disableOK) return;
// If nothing has change, we close the windows with the closeDlg function
if (_Qualification == getQualification() && _objName == textName.getValue() && _objFormula == formulaValue() && _baseAssociatedDimID == _associatedDimID)
{
if (!bApplyBtn)
closeDlg ()
return;
}
/*
//TODO
// warn that the associated custom sort is destroyed if we change the var qualif or Formula ADAPT00452281
if (getQualification() != _Qualification || _objFormula != formulaValue()) {
for (var i=0; i < _varCounts; i++) {
var obj = _variableObjects[i]
if (obj && (obj.name == textName.getValue())) {
if (p.isCustomSort(obj.id)) {
p.showPromptDialog("修改此变量将删除其关联的自定义排序顺序。是否要继续？","警告",p._promptDlgWarning, okCBWork)
return
}
}
}
}
*/
okCBWork()
}
function callOKCBWork() {
_warningModif = false
okCBWork()
}
function okCBWork()
{
_Qualification = getQualification();
validateStringFormula();
var nAction = 2 //creation variable
//AURORA: we can rename a variable 
if(_isEditing) nAction=3 //replace variable
if(_isFormulaEditor)  nAction=1 //replace formula
if(_isFromOtherDialog) nAction=4 //formula validation
if (_warningModif && (nAction == 3)) { //ADAPT01610180
//function showPromptDialog(msg,title,iPromptType,yesCB,noCB, yesText, noText)
//iPromptType 0=_promptDlgInfo 1=_promptDlgWarning 2=_promptDlgCritical
p.showPromptDialog("确实要修改此变量吗？","警告", p._promptDlgWarning, callOKCBWork, closeDlg, "是", "否")
return
}
var params=getURLParams()
var sName = remSpaceAround(textName.getValue())
if(params)
{
var url = p._root+"processFormulaValidation"+p._appExt+params
self.document.submitForm.action = url;
self.document.submitForm.target = "validate"
self.document.submitForm.sName.value = sName
self.document.submitForm.sVarId.value = _objId
self.document.submitForm.sFormula.value = formulaValue()
self.document.submitForm.sQualif.value = getQualification()
self.document.submitForm.sAssociatedDim.value =_associatedDimID
self.document.submitForm.nAction.value = nAction;
p.wt()
self.document.submitForm.submit();
//frameNav("validate",p._root+"processFormulaValidation"+p._appExt+params+"&sFormula="+p.convURL(formulaValue())+"&sName="+p.convURL(sName)+"&sQualif="+p.convURL(_Qualification)+"&action="+nAction)
}
}
//callback of close dialog
function closeDlg(bApplyBtn)
{
if(bApplyBtn)
{
_isApplyMode=false;
_isEditing=true;
_objFormula=formulaValue();
_objName=textName.getValue();
}
else
{
clearInterval(_timeInterval); 
if(_timeWait!=null) clearTimeout(_timeWait)
closeCompletionPopup()
variableEditorDlg.show(false)
}
}
//callback of focus and blur event for formulaTxt
function formulaTxt_blur(){_formulaTxtFocus = false;}
function formulaTxt_focus(){_formulaTxtFocus = true;}
function formulaTxt_storeCaret()
{
if (this.createTextRange) 
this.caretPos = _curDoc.selection.createRange().duplicate(); 
}
//escape action: close popup if necessary
function formulaTxt_cancel(e)
{
if(_shownPopup)
{
var e=_ie?_curWin.event:e
eventCancelBubble(e)
e.returnValue=false
if(this.id==completionPopup.id)
setTimeout("delayedRestoreCursor()",1)
closeCompletionPopup();
}
}
//callabck from keydown event with a delay that why we do not have the event anymore
function formulaTxt_change(k)
{
//var k=eventGetKey(e)
//window.status='down touche '+k + '('+ (t) +')'; t=t+1;
//if down arrow key then give focus to popup
switch(k)
{
case 40:
if(_shownPopup)
{
completionList.select(0,true,null,true,true)
completion_arrowOver()
return false;
}
break;
}
//save oldFormula
_oldFormula = _newFormula;
_newFormula = formulaValue();
//window.status=_newFormula;
//Empty Type
if (_oldFormula != _newFormula)
textTypeValue ("");
//enable OK button if name and formula is not null
updateButtons()
if(_oldFormula == _newFormula)//not imprimable caracter
closeCompletionPopup()
initTimeWait()
}
//enter action: validate formula if necessary
function formulaTxt_validate(e)
{
//TODO:allowCR
if (e.ctrlKey) 
{
//formulaValue(formulaValue()+"\r\n");
formulaTxt_change(13);
return true;
}
eventCancelBubble(e)
var f=formulaValue()
if(f!="" && _objFormula!=f)
validateFormula()
}
//call from validate button CB
//validate the sytax of definition
function validateFormula()
{
closeCompletionPopup();
validateStringFormula()
var params=getURLParams()
if(params)
{
var url = p._root+"processFormulaValidation"+p._appExt+params
self.document.submitForm.action = url;
self.document.submitForm.target = "validate"
self.document.submitForm.sName.value = ""
self.document.submitForm.sFormula.value = formulaValue()
self.document.submitForm.sQualif.value = ""
self.document.submitForm.sAssociatedDim.value =""
self.document.submitForm.nAction.value = 0;
self.document.submitForm.submit();
p.wt()
//frameNav("validate",p._root+"processFormulaValidation"+p._appExt+params+"&sFormula="+p.convURL(formulaValue())+"&action=0")
}
}
function resetFormula()
{
formulaValue(_objFormula);
}
//called after formula validation
//when comming from Other Dialog
function setFormulaCB()
{
p.hideBlockWhileWaitWidget()
eval(_callBackOut+'(formulaValue(),formulaKind)')
closeDlg()
}
//following the qualification choose by user, update the linked dimension zone
function updateLinkBtn()
{
if(getQualification() == "detail")
{
linkDimZone.show(true);
}
else
{
//reset _associatedDimName because it is the only way to disassociated a dim to detail
_associatedDimName="选择一个维"
_associatedDimID = ""
linkDimZone.show(false);
}
linkedDim.setValue(_associatedDimName);
}
// show associatedDimDlg to allow user to select dp dimension to associate to detail
function displayDimList()
{
p.fillDictionaryTree(dimTree,self,"dp",null,filterDimension); //display by dp because we want only dp dimension
associatedDimDlg.show(true);
}
//enable or disable OK in associatedDimDlg
//clickCB callback in treeview
function updateDimOKBtn()
{
var sel = dimTree.getSelectedItem();
if( sel && sel.userData != null && 
  ( sel.userData.kind == _ObjType.dim || 
    sel.userData.kind == _ObjType.hierarchy || 
    sel.userData.kind == _ObjType.defaultHierarchy ||
sel.userData.kind == _ObjType.link_dim ||
    sel.userData.kind == _ObjType.level))
            {    
dimOK.setDisabled(false);//only if selected a dimension and not a class
            }
else
dimOK.setDisabled(true);
}
function validateDimCB()//dbclickCB in treeview
{
if(!dimOK.isDisabled())
associatedDimOK();
}
//OK action in associatedDimDlg
function associatedDimOK()
{
var sel = dimTree.getSelectedItem();
associatedDimClose();
var data = sel?sel.userData:null;
if(data == null )return; //safe test
_associatedDimID= data.id;
_associatedDimName = sel.name;
linkedDim.setValue(_associatedDimName);
//ADAPT00492378: give focus to textName (variableEditorDlg) after associatedDimDlg had closed
textName.focus();
}
//close associatedDimDlg 
function associatedDimClose()
{
associatedDimDlg.show(false);
//ADAPT00492378: give focus to textName (variableEditorDlg) after associatedDimDlg had closed
textName.focus();
}
//=====================================================================
//tree construction and callback funcions
//====================================================================
//deselect other trees selection when selection in a tree
function unselectOtherTrees(tree)
{
if(tree.id !=dicTree.id ) dicTree.unselect()
if(tree.id !=fctTree.id ) fctTree.unselect()
if(tree.id !=opeTree.id ) opeTree.unselect()
}
//clickCB in treeviews (dicTree,fctTree,opeTree)
//update help zone
function clickCB(data)
{
var tree = this;
_ddText=""
_helpText=""
unselectOtherTrees(tree);
if (_ie)
{
var sel = _curDoc.selection.createRange().duplicate();
sel.execCommand("Unselect");
}
if(data)
{
if(formulaValue()=="")_ddText="="
        if(tree.id ==dicTree.id )
        {   
_ddText+=data.snapName? data.snapName:""
if(data.name)
        _helpText="<b>"+convStr(data.name,true,true)+"</b><br>"+(data.desc?convStr(data.desc,true,true):"")        
        }
        else if(tree.id ==fctTree.id)
        {
        _ddText+=data.name+ ((data.syntax.indexOf("(")>=0)?"()":""); //some functions does not have parenthesis
        _helpText="<b>"+convStr(data.syntax,true,true)+"</b><br>"+convStr(data.hint,true,true)
        _helpText+=addHelpLink(data.id);
        }
        else //opeTree
        {          
        _ddText+=data.name 
_helpText="<b>"+convStr(data.syntax,true,true)+"</b><br>"+convStr(data.hint,true,true)
        //_helpText="<b>"+convStr(data.name,true,true)+"</b>";
        _helpText+=addHelpLink(data.id);
        }
        } 
        else if((tree.id.substr(0,9))=="iconLogOp")
        {
        _ddText=tree.text;
        dclickCB(true)
        }       
        //update help zone
        helpFctArea.setHTML(_helpText)                
}
//dclickCB in treeviews (dicTree,fctTree,opeTree)
function dclickCB(data)
{
if (!data) return // click on +-
var hasParenthesis = (data && data.syntax && data.syntax.indexOf("(")>=0);
var hasParameters = (hasParenthesis && data.syntax && data.syntax.indexOf("()")<0);
var lyr=formulaTxt.layer
//if (_ie) 
if(lyr.createTextRange && lyr.caretPos)
{
var sel = lyr.caretPos; 
sel.text = sel.text.charAt(sel.text.length - 1) == ' ' ? _ddText + ' ' : _ddText; 
if(data && data.category && hasParameters) //fct with parameters
sel.move('character',-1);
sel.select();
}
else if (lyr.setSelectionRange) 
{
lyr.focus()
var len = lyr.selectionEnd;
lyr.value = lyr.value.substr( 0, len )
    + _ddText 
    + lyr.value.substr( len );
if(data && data.category && hasParameters) //fct
lyr.setSelectionRange(len+_ddText.length-1,len+_ddText.length-1);
else
lyr.setSelectionRange(len+_ddText.length,len+_ddText.length);
} 
else 
{
lyr.value += _ddText;
}
//save formula
_oldFormula = _newFormula;
_newFormula = formulaValue();
// Empty type
textTypeValue ("");
}
//build fctTree
function buildFctTree()//fctTree
{
var arr = p._formulaFcts
if(arr==null) return;//safe test
var len = arr.length
var prevCat="",allCatID="1", sDesc=""
var newTreeElt=null;
if (len>0)
{
for (var i=0; i < len; i++)
{
var item = arr[i]
if(prevCat!=item.category)
{
prevCat=item.category
newTreeElt=newTreeWidgetElem(1,prevCat);
fctTree.add(newTreeElt);
}
if(newTreeElt!=null)
newTreeElt.add(newTreeWidgetElem(-1, item.name, item));
//newTreeElt.add(newTreeWidgetElem(12, item.name, item));
//fill _arrFctOpe
if(allCatID == item.categoryId)
{
sDesc="<b>"+convStr(item.syntax,true,true)+"</b><br>"+convStr(item.hint,true,true)
sDesc+=addHelpLink(item.id);
//data.syntax.indexOf("(")>=0)
_arrFctOpe[_arrFctOpe.length]=newIconObj(item.name+((item.syntax.indexOf("(")>=0)?"()":""),12,sDesc)
}
}
}
}
//build opeTree
function buildOpeTree() //opeTree
{
var arr = p._formulaOpers
var sDesc="";
if(arr == null) return; //safe test
var len = arr.length
if (len>0)
{
for (var i=0; i < len; i++)
{
var item = arr[i]
if( _arrLogOp.indexOf(item.name) > -1) continue;
opeTree.add(newTreeWidgetElem(-1, item.name, item));
//fill _arrFctOpe
sDesc="<b>"+convStr(item.syntax,true,true)+"</b><br>"+convStr(item.hint,true,true)
sDesc+=addHelpLink(item.id);
//sDesc="<b>"+convStr(item.name,true,true)+"</b>"+addHelpLink(item.id);
_arrFctOpe[_arrFctOpe.length]=newIconObj(item.name,13,sDesc)
}
}
}
//====================================================================
//drag and drop
//====================================================================
function dragCB(source)
{
_curWin.event.dataTransfer.setData("Text", ""+_ddText)
}
function acceptDropCB(source,target,ctrl,shift)
{
return false
}
function dropCB(source,target,ctrl,shift)
{
}
function textDropCB()
{/*
if ((typeof(_globalDDD) != "undefined")&&(_globalDDD!=null))
{
//_curWin.event.dataTransfer.setData("Text", _globalDDD.getSelectedItem().name)
_curWin.event.dataTransfer.setData("Text", _ddText)
}
return true*/
if (typeof(_ddText)!="undefined" && _ddText != "")
{
_oldFormula = _newFormula;
_newFormula = _newFormula + _ddText;
//Empty Type
if (_oldFormula != _newFormula)
textTypeValue ("");
}
return true
}
//====================================================================
//autocompletion
//====================================================================
//wait 1 sec befor launch the completion except if aucompletion has already start
function initTimeWait()
{
if(_timeWait!=null) clearTimeout(_timeWait)
if(_shownPopup)
launchAutoCompletion();
else
_timeWait=setTimeout("launchAutoCompletion()",1000)
}
//launch autocompletion workflow
function launchAutoCompletion()
{
_timeWait=null
//search text to complete
lastMatchTxt=_currentMatchTxt
_currentMatchTxt=getMatchText().toLowerCase()
if(_currentMatchTxt!="")
getMatchTextArray()
else
closeCompletionPopup()
}
//get the current cursor position to determine what is the match text to complete
//base on _oldFormula and _newFormula difference
//NOTE: cannot be determined by textarea info :(
function getCursorPosition()
{
if(_oldFormula == _newFormula) return -1;
var i, len=_oldFormula.length, nlen = _newFormula.length
for(i=0;i<len;i++)
{
if(i>=nlen || _oldFormula.charAt(i)!=_newFormula.charAt(i))
break;
}
if(_newFormula!="" && len<nlen)
return i+1;
else
return i;
}
//determine the text to complete (in funciton of separator before and after)
function getMatchText()
{
var cursorPos = _cursorPos= getCursorPosition();
var startFormula = "" , endFormula = ""
if(cursorPos == -1 || _newFormula=="")return "";
//else if(cursorPos == 0) endFormula = _newFormula
//else if(cursorPos == endFormula.length) endFormula = _newFormula
else
{
startFormula = _newFormula.substring(0,cursorPos)
endFormula = _newFormula.substring(cursorPos,_newFormula.length)
}
if(startFormula=="")
{ 
return "";
}
//alert(startFormula +"/" +endFormula)
var lenSep = _arrSeparators.length, sep="",startIdx=0, endIndx=0
var tmpStart=startFormula,tmpEnd=endFormula
for(var i=0;i<lenSep;i++)
{
var sep = _arrSeparators[i]
if((startIdx = tmpStart.lastIndexOf(sep))>-1)
{
tmpStart=tmpStart.substring(startIdx+1,tmpStart.length)
}
if((endIdx=tmpEnd.indexOf(sep))>-1)
{
tmpEnd=tmpEnd.substring(0,endIdx)
}
}
if(tmpStart=="")
{
return ""
}
else
{
_firstPart = _lastPart =""
_firstPart=startFormula.substring(0,startFormula.length-tmpStart.length)
_lastPart=endFormula.substring(tmpEnd.length,endFormula.length)
return tmpStart+tmpEnd
}
}
function completeObjects()
{
var len = _arrAvailableObjects.length; obj=null, sDesc="", icnKind=null;
for(var i=0;i<len;i++)
{
obj = _arrAvailableObjects[i].name.toLowerCase()
if(obj.indexOf(_currentMatchTxt) == 0)
{
obj=_arrAvailableObjects[i];
sDesc = "<b>"+convStr(obj.name,true,true)+"</b><br>"+(obj.desc?convStr(obj.desc,true,true):"");
icnKind = p.mapKindToTreeIcon(obj.kind);
_arrMatchTxt[_arrMatchTxt.length]={name:obj.snapName,icon:icnKind.idx, desc:sDesc,url:icnKind.src} 
}
}
}
function getMatchTextArray()
{
if(_currentMatchTxt.indexOf(_lastMatchTxt)==0 && _lastMatchTxt!="")
{
_arrAllTxt = arrayGetCopy(_arrMatchTxt)
_arrMatchTxt.length=0;
for(var i=0;i<_arrAllTxt.length;i++)
{
if((_arrAllTxt[i].name.toLowerCase()).indexOf(_currentMatchTxt) == 0)
_arrMatchTxt[_arrMatchTxt.length]=_arrAllTxt[i]
}
completeObjects()
}
else 
{
_arrAllTxt = arrayGetCopy(_arrFctOpe)
_arrMatchTxt.length=0;
for(var i=0;i<_arrAllTxt.length;i++)
{
if((_arrAllTxt[i].name.toLowerCase()).indexOf(_currentMatchTxt) == 0)
_arrMatchTxt[_arrMatchTxt.length]=_arrAllTxt[i]
}
completeObjects()
}
completionList.deleteAll()
for(var j=0;j<_arrMatchTxt.length;j++)
{
completionList.add(newTreeWidgetElemParams({
iconId:_arrMatchTxt[j].icon,
name:_arrMatchTxt[j].name,
userData:_arrMatchTxt[j].desc,
iconUrl:_arrMatchTxt[j].url
}));
}
completionList.rebuildHTML()
if(_arrMatchTxt.length>0 && _formulaTxtFocus)
{
var lyr=formulaTxt.layer
if (lyr.createTextRange)
{
var rng = _curDoc.selection.createRange().duplicate();
completionPopup.show(true,rng.offsetLeft,rng.offsetTop+12)
_shownPopup=true
}
else if(lyr.setSelectionRange )
{
var pos = getPos(lyr)
var height=formulaTxt.getHeight()
completionPopup.show(true,pos.x,pos.y+height+1)
_shownPopup=true
}
}
else
{
closeCompletionPopup()
}
}
function replaceCompletionText(s,isFct)
{
var lyr=formulaTxt.layer
if (lyr.createTextRange)
{
formulaValue(_firstPart+s);
formulaTxt.focus();
var rng = _curDoc.selection.createRange().duplicate();
rng.text=_lastPart;
rng.move("character",-(_lastPart.length))
rng.select();
}
else if(lyr.setSelectionRange )
{
var len = _firstPart.length+s.length;
lyr.value = _firstPart+s+_lastPart;
if(isFct)
lyr.setSelectionRange(len-1,len-1);
else
lyr.setSelectionRange(len,len);
}
}
function completion_mouseOver(elem)
{
elem.select(null,null,true)
_helpText=elem.userData?elem.userData:"" 
        helpFctArea.setHTML(_helpText)                         
}
function completion_arrowOver()
{
var elem=completionList.getSelectedItem()
_helpText=elem.userData?elem.userData:"" 
        helpFctArea.setHTML(_helpText)                         
}
function completion_click(data,isFromKeyArrow)
{
if(isFromKeyArrow) 
completion_arrowOver()
else 
completion_insert()
}
function completion_select()
{
formulaTxt.focus();
}
function completion_insert()
{
var s = completionList.getSelectedItem().name;
var isFct=(completionList.getSelectedItem().iconId==12)
closeCompletionPopup()
replaceCompletionText(s,isFct)
_oldFormula = _newFormula;
_newFormula = formulaValue();
setTimeout("formulaTxt.focus()",1)
}
function closeCompletionPopup()
{
if(_shownPopup)
{
_shownPopup=false
completionPopup.show(false)
}
}
function addHelpLink(id)
{
return "";
}
</script>
</head>
<body class="dialogzone" onload="setTimeout('loadDialog()',1)">
<iframe name="validate" src="../../../../dhtmllib/empty.html"></iframe>
<!-- Hidden form -->
<form target="Report" style="display:none" name="submitForm" method="post" action="">
<input type="hidden" name="sName" id="sName">
<input type="hidden" name="sVarId" id="sVarId">
<input type="hidden" name="sFormula" id="sFormula">
<input type="hidden" name="sQualif" id="sQualif">
<input type="hidden" name="sAssociatedDim" id="sAssociatedDim">
<input type="hidden" name="nAction" id="nAction">
<input type="hidden" name="bidon" id="bidon">
</form>
</body>
</html>
